<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <script src="file:///android_asset/JSBridge.js" type="text/javascript">
    </script>
    <script type="text/javascript">
        function promptAndSendMsg(){
         prompt("这是来自js的消息");
        }

    </script>
    <script type="text/javascript">
       var callbacks=new Array();
//1.jsCallAndroid
function jsCallAndroid(obj,method,params,callback){
    //保存callback
    var port=callbacks.length;
    callbacks[port]=callback;
    //组合出符合规则的URL,并传递给java层
    var url='JSBridge://'+obj+':'+port+'/'+method+'?'+JSON.stringify(params);
    window.prompt(url);
}
//2.onAndroidFinished
function onAndroidFinished(port,jsonObj){
//从callback取出对应的回调函数
alert(JSON.stringify(jsonObj));
    var callback=callbacks[port];
    callback(jsonObj);
    //从callbacks中删除callback
    delete callbacks[port];
}

    </script>

</head>
<body>
<div>
    <button onclick="promptAndSendMsg()">提示框并向Java层传递消息</button>
<!--    <button onclick="JSBridge.jsCallAndroid('JSBridge','showToast',{'msg':'Hello I come from JS'}, function(res){alert(JSON.stringify(res)) })"-->
<!--            style="margin -top:10px;">Js调用Android-->
<!--    </button>-->
    <button onclick="jsCallAndroid('JSBridge','showToast',{'msg':'Hello I come from JS'}, function(res){alert(JSON.stringify(res)) ;})"
            style="margin -top:10px;">Js调用Android
    </button>
</div>
</body>
</html>
